
const requireImg = (imgPath) => {
  return new URL(`../assets/img/${imgPath}`, import.meta.url).href;
};
import { ref, onMounted, computed, reactive } from "vue";
import { getLatest } from "@/api/User.js";
const currencyList = reactive([
  {
    "Id": 20,
    "Symbol": "USD",
    "ExRate": "1",
    src:requireImg('USD.png'),
    "Name": "United States Dollar"
  },
    {
      "Id": 1,
      "Symbol": "AUD",
      "ExRate": "1.466715",
      "Name": "Australian Dollar",
      src:requireImg('AUD.png')
    },
    {
      "Id": 2,
      "Symbol": "CAD",
      "ExRate": "1.314535",
      "Name": "Canadian Dollar",
      src:requireImg('CAD.png')
    },
    {
      "Id": 3,
      "Symbol": "CHF",
      "ExRate": "0.858485",
      "Name": "Swiss Franc",
      src:requireImg('CHF.png')
    },
    {
      "Id": 4,
      "Symbol": "CNY",
      "ExRate": "7.187497",
      "Name": "Chinese Yuan",
      src:requireImg('CNY.png')
    },
    {
      "Id": 5,
      "Symbol": "DKK",
      "ExRate": "6.65313",
      "Name": "Danish Krone",
      src:requireImg('DKK.png')
    },
    {
      "Id": 6,
      "Symbol": "GBP",
      "ExRate": "0.774805",
      "Name": "British Pound Sterling",
      src:requireImg('DBP.png'),
    },
    {
      "Id": 7,
      "Symbol": "HKD",
      "ExRate": "7.81217",
      src:requireImg('HKD.png'),
      "Name": "Hong Kong Dollar"
    },
    {
      "Id": 8,
      "Symbol": "IDR",
      "ExRate": "14994.55",
      src:requireImg('IDR.png'),
      "Name": "Indonesian Rupiah"
    },
    {
      "Id": 9,
      "Symbol": "INR",
      "ExRate": "82.052503",
      src:requireImg('INR.png'),
      "Name": "Indian Rupee"
    },
    {
      "Id": 10,
      "Symbol": "JPY",
      "ExRate": "139.552942",
      src:requireImg('JPY.png'),
      "Name": "Japanese Yen"
    },
    {
      "Id": 11,
      "Symbol": "KRW",
      "ExRate": "1271.910145",
      src:requireImg('KRW.png'),
      "Name": "South Korean Won"
    },
    {
      "Id": 12,
      "Symbol": "MYR",
      "ExRate": "4.551011",
      src:requireImg('MYR.png'),
      "Name": "Malaysian Ringgit"
    },
    {
      "Id": 13,
      "Symbol": "NOK",
      "ExRate": "10.00652",
      src:requireImg('NOK.png'),
      "Name": "Norwegian Krone"
    },
    {
      "Id": 14,
      "Symbol": "NZD",
      "ExRate": "1.59409",
      src:requireImg('NZD.png'),
      "Name": "New Zealand Dollar"
    },
    {
      "Id": 15,
      "Symbol": "PHP",
      "ExRate": "54.519497",
      src:requireImg('PHP.png'),
      "Name": "Philippine Peso"
    },
    {
      "Id": 16,
      "Symbol": "RUB",
      "ExRate": "91.037505",
      src:requireImg('RUB.png'),
      "Name": "Russian Ruble"
    },
    {
      "Id": 17,
      "Symbol": "SGD",
      "ExRate": "1.324505",
      src:requireImg('SGD.png'),
      "Name": "Singapore Dollar"
    },
    {
      "Id": 18,
      "Symbol": "THB",
      "ExRate": "34.064021",
      src:requireImg('THB.png'),
      "Name": "Thai Baht"
    },
    {
      "Id": 19,
      "Symbol": "TWD",
      "ExRate": "31.098504",
      src:requireImg('TWD.png'),
      "Name": "New Taiwan Dollar"
    },
 
    {
      "Id": 21,
      "Symbol": "VND",
      "ExRate": "23645",
      src:requireImg('VND.png'),
      "Name": "Vietnamese Dong"
    }
  ])
  const getCurrency = (id)=> {
    let item = currencyList.find(res=>res.Id==id)
    if(item){
      return item
    }else{
      return {}
    }
  }
  const setRate = () =>{
     currencyList.forEach(res=>{
      getLatest(res.Symbol).then(data=>{
        res.ExRate = data.data
      })
     })
  }
  export {setRate,currencyList,getCurrency}